<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../../练习/vue-base_ddx/js/vue.js"></script>
</head>
<body>
    <div class="box">
    <h1>{{msg}}</h1>
    <button @click="like">喜欢王佳兴</button>
    <button @click="give">zheshu</button>
    </div>
    <script>
        const vm = new Vue({
            el:'.box',
            data:{
                msg:'很喜欢王佳兴！！'
            },
            mounted(){
                this.$on('wangjiaxing',(msg)=>{
                    console.log('你喜欢我嘛？');
                    console.log(msg);
                }),
                this.$on('zheshu',(info)=>{
                    console.log('内容');
                    console.log(info);
                })
            },
            methods:{
                like(){
                    // 想去触发$emit
                    this.$emit('wangjiaxing','么么哒');
                },
                give(){
                    this.$emit('zheshu',{name:'yangyang',age:18})
                }
            }
        })
        // console.log(vm);
        // // 绑定事件 可以自己进行定义 $on('自定义的事件名',回调函数(()=>{}))
        // console.log(vm.$on);
        // // 触发 分发事件（调用事件）$emit("事件名",传给回调函数的参数)
        // console.log(vm.$emit);
    </script>
</body>
</html>